package com.ming.easyDevelop.controller;

import com.ming.easyDevelop.controller.base.BaseController;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import com.ming.easyDevelop.service.UserCouponsService;
import com.ming.easyDevelop.controller.base.ValidListBean;
import javax.validation.Valid;
import com.ming.easyDevelop.entity.po.UserCoupons;
import com.ming.easyDevelop.entity.vo.ResponseVo;
import com.ming.easyDevelop.entity.query.UserCouponsQuery;
import java.util.List;
/**
 * @Description  Controller API
 * @Author ming
 * @Date 2024/07/10
 */
@RequestMapping("/api/userCoupons")
@RestController
public class UserCouponsController extends BaseController {
	@Resource
	private UserCouponsService userCouponsService;

	@RequestMapping("/list")
	public ResponseVo getDataList(UserCouponsQuery query){
		return getSuccessResponseVo(this.userCouponsService.findListByParam(query));
	}
	@PostMapping("/add")
	public ResponseVo add(@Valid @RequestBody UserCoupons bean){
		this.userCouponsService.add(bean);
		return getSuccessResponseVo(null);
	}

	@PostMapping("/addOrUpdate")
	public ResponseVo addOrUpdate(@Valid @RequestBody UserCoupons bean){
		this.userCouponsService.addOrUpdate(bean);
		return getSuccessResponseVo(null);
	}

	@PostMapping("/addBatch")
	public ResponseVo addBatch(@RequestBody ValidListBean<UserCoupons> list){
		this.userCouponsService.addBatch(list.getData());
		return getSuccessResponseVo(null);
	}

	@PostMapping("/addOrUpdateBatch")
	public ResponseVo addOrUpdateBatch(@RequestBody ValidListBean<UserCoupons> list){
		this.userCouponsService.addOrUpdateBatch(list.getData());
		return getSuccessResponseVo(null);
	}

	/**
	 * 根据UserIDAndCouponCode查询
	 */
	@GetMapping("/userIDAndCouponCode")
	public ResponseVo getByUserIDAndCouponCode(Integer userID, String couponCode){
		return getSuccessResponseVo(this.userCouponsService.getByUserIDAndCouponCode(userID, couponCode));
	}

	/**
	 * 根据UserIDAndCouponCode更新
	 */
	@PutMapping("/userIDAndCouponCode")
	public ResponseVo updateByUserIDAndCouponCode(@Valid UserCoupons bean, Integer userID, String couponCode){
		this.userCouponsService.updateByUserIDAndCouponCode(bean,userID, couponCode);
		return getSuccessResponseVo(null);
	}

	/**
	 * 根据UserIDAndCouponCode删除
	 */
	@DeleteMapping("/userIDAndCouponCode")
	public ResponseVo deleteByUserIDAndCouponCode(Integer userID, String couponCode){
		this.userCouponsService.deleteByUserIDAndCouponCode(userID, couponCode);
		return getSuccessResponseVo(null);
	}

}